#pragma once;

#include "GLFWApp.h"
#include "rigidbody.h"
#include "collisiondata.h"
#include "contact_resolver.h"
#include "collision_primitive.h"
#include <vector>
#include "Box.h"
#include "ball.h"
#include "world.h"

using namespace TorPhysix;

#define MAX_BALLS 3*3*2+1
#define MAX_BOXES 24



class App : public GLFWApp
{
public:
	App();
	void update(); // update physics
	void render();
	

private:

	void generateContacts(); // use collision detector to generate contacts
	void updateObjects(real duration);
	void resetPhysics(); // reset objects to original state

	void renderDebugInfo();
	void updateWorldMouseCoordinates();

	void onKey(const int key, const bool pressed);

private:
	float camVertical, camHorizontal;
	float camZoom;
	int oldMouseX, oldMouseY;

	Vec3f mousePointer;
	Vec3f oldMousePointer;
	Vec3f mousePointerVelocity;

	Vec3f mouseSamples[5];
	int mouseSampleCount;

	double renderTime;
	double physicsTime;

	bool wireframe;

	int stepOneFrame;
	int simulateRealtime;
	int simIterations;
	std::vector<TorPhysix::PhysicsObject*> physObjList;

	World physicsWorld;

	//const static unsigned maxContacts = (MAX_BALLS+MAX_BOXES)*8;
	//TorPhysix::Contact contacts[maxContacts];
	std::vector<TorPhysix::Contact> contacts;

	TorPhysix::CollisionData cData;
	TorPhysix::ContactResolver resolver;
};